<template>
  <div class="village_main">
    <head-top goBack="true" head-title="小区公告"></head-top>
    <div class="village_content">
    </div>
    <mt-cell :title="item.title" :label="item.author" :value="item.created_at*1000 | dateFmt(('YYYY-MM-DD'))" is-link :to="'/home/VillageDetail/'+item.id" v-for="(item,index) in detail" :key="index"></mt-cell>
    <div class="default" v-show="!detail.length && !noResult">
      <p>数据加载中</p>
    </div>
    <div class="default1" v-show="noResult">
      <p>抱歉！暂无数据</p>
    </div>
  </div>
</template>
<style lang="scss">
  @import "../../common/sass/mixin.scss";

  .village_main {
    padding-top: 40px;
    .mint-cell-text{
      @include ellipsis(1);
      line-height: 20px;
    }
    .mint-cell-label{
      @include ellipsis(1);
      line-height: 18px;
      color: #0078de;
    }
    .mint-cell {
      min-height: 55px;
    }
    .mint-cell-wrapper{
      background-size: 100% 1px;
    }
    .mint-cell-value.is-link{
      margin-right: 10px;
      font-size: 12px;
    }
  }
  .default {
    width: 100%;
    flex: 1;
    display: inline-flex;
    padding-top: 100px;
    justify-content: center;
    align-items: center;
    background: url("../../assets/loading.gif") no-repeat;
    background-size: 40px 40px;
    background-position: center;
    padding-bottom: 100px;
    p {
      font-size: 15px;
      color: #666;
      margin-top: 100px;
    }
  }

  .default1 {
    width: 100%;
    flex: 1;
    display: inline-flex;
    padding-top: 100px;
    justify-content: center;
    align-items: center;
    background: url("../../assets/default.png") no-repeat;
    background-size: 100px 100px;
    background-position: center;
    padding-bottom: 140px;
    p {
      font-size: 15px;
      color: #0b7ad9;
      margin-top: 180px;
    }
  }
</style>
<script>
  import headTop from '../header/Header.vue'
  import commonUrl from '../../common/js/commonUrl.js'

  export default {
    name: 'VillageNotice',
    data () {
      return {
        detail1: [],
        noResult: false
      }
    },
    components: {
      headTop
    },
    // created () {
    //   this.getVillageList()
    // },
    // 设置缓存从哪个页面返回
    beforeRouteEnter: (to, from, next) => {
      if (from.name === 'VillageDetail') {
        to.meta.isBack = true
      }
      next()
    },
    activated () {
      if (!this.$route.meta.isBack) {
        this.getVillageList()
      }
      this.$route.meta.isBack = false
    },
    methods: {
      getVillageList () {
        this.noResult = false
        const url = commonUrl.apihost + 'index.php/home/article/announce/?areas_id=' + this.$route.params.id
        this.$http.get(url).then(res => {
          if (res.status === 200) {
            this.detail1 = res.data.data
          }
          if (this.detail1.length === 0) {
            this.noResult = true
          } else {
            this.noResult = false
          }
        })
      }
    },
    computed: {
      detail () {
        return this.detail1.reverse()
      }
    }
  }
</script>
